<?php

include('pagina.php');
include('database.php');
include('auth.php');
include('core.php');

// Verifica se tem permissao
validaPermissao(3);

// Verifica se ha cliente para ver
if (!$_GET['id'])
{
	forbidden();
}

// Busca todos os dados do cliente
$customer = query_fetch("SELECT * FROM customers WHERE id='{$_GET['id']}'");

// Se nao existe, cai fora
if (!$customer)
{
    response_404();
}

$customer_contact = query_fetch("SELECT * FROM contacts WHERE id={$customer['contact_id']}");

// Inicia cabecalho da pagina
pagina_inicio('ParkSys - Customer');
pagina_head();

// Mostra opcoes
echo "<ul id=opcoes>";
echo "<li><a href='customer_edit.php?id={$customer['id']}'><img src='img/edit.png' alt=''>Edit Customer</a></li>";
echo "<li><a href='reports.php?customer={$customer['id']}'><img src='img/report.png' alt=''>Event reports from this customer</a></li>";
echo "<li><a href='incomes_expenses.php?customer={$customer['id']}'><img src='img/payday.png' alt=''>Incomes and Expenses</a></li>";
echo "<li><a href='customer.php?id={$customer['id']}&amp;print=1' target='_blank'><img src='img/print.png' alt=''>Print</a></li>";
echo "</ul><br><br>";

// Renderiza dados fixos do cliente
echo "<div class=dados_estaticos>";
echo "<h1>Customer</h1><br>";
echo "<dl>";
echo "<dt>Name</dt><dd>{$customer_contact['name']}</dd>";
echo "<dd><hr><h2>Contact</h2></dd>";
echo "<dt>Address</dt><dd><address>",
"{$customer_contact['number']}, {$customer_contact['street']}, {$customer_contact['complement']} ",
"zip: {$customer_contact['zipcode']}, {$customer_contact['city']} - {$customer_contact['state']}.</address></dd>";
if ($customer_contact['phone'])
	echo "<dt>Phone number</dt><dd>{$customer_contact['phone']}</dd>";
if ($customer_contact['cellphone'])
	echo "<dt>Mobile number</dt><dd>{$customer_contact['cellphone']}</dd>";
if ($customer_contact['email'])
	echo "<dt>Email</dt><dd>{$customer_contact['email']}</dd>";
if ($customer['obs'])
		echo "<dd><hr></dd><dt>Observations</dt><dd>{$customer['obs']}</dd>";
        
echo "</dl>";
echo "</div>";

// Finaliza pagina
pagina_fim();
?>
